/** 
 * Copyright 2010 Erlacher Felix, Estgfaeller Wolfgang, Ferula Patrick
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package at.socialconference.app.model;

import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;
import at.socialconference.inter.model.User;

public class AUser extends User implements Parcelable{

	public AUser[] aContacts;

	public AUser(Integer id, String firstname, String lastname, String gender,
			String phone, String title, String webpage, String dblp,
			String city, String country, String address, String zip, String mail,String twtoken,String twsecret,ArrayList<User> contacts) {
		super(id, firstname, lastname, gender, phone, title, webpage, dblp, city,
				country, address, zip, mail, contacts,twtoken,twsecret);

	}


	public AUser(Parcel in) {
		super();
		super.setId(in.readInt());
		super.setFirstname(in.readString());
		super.setLastname(in.readString());
		super.setGender(in.readString());
		super.setPhone(in.readString());
		super.setWebpage(in.readString());
		super.setDblp(in.readString());
		super.setCity(in.readString());
		super.setCountry(in.readString());
		super.setAddress(in.readString());
		super.setZip(in.readString());
		super.setMail(in.readString());
		super.setTw_access_token(in.readString());
		super.setTw_access_secret(in.readString());
		Parcelable[] tmp = (Parcelable[]) in.readParcelableArray(AUser.class.getClassLoader());
		if(tmp!=null){
			aContacts = new AUser[tmp.length];
			for(int i=0;i<aContacts.length;i++){
				aContacts[i] = (AUser)tmp[i];
				
			}
		}
	}

	public AUser(User u) {
		super.setId(u.getId());
		super.setFirstname(u.getFirstname());
		super.setLastname(u.getLastname());
		super.setGender(u.getGender());
		super.setPhone(u.getPhone());
		super.setWebpage(u.getWebpage());
		super.setDblp(u.getDblp());
		super.setCity(u.getCity());
		super.setCountry(u.getCountry());
		super.setAddress(u.getAddress());
		super.setZip(u.getZip());
		super.setMail(u.getMail());
		super.setContacts(u.getContacts());
		super.setTw_access_token(u.getTw_access_token());
		super.setTw_access_secret(u.getTw_access_secret());
		if(u.getContacts()!=null){
			aContacts = new AUser[u.getContacts().size()];
			for(int i=0;i<aContacts.length;i++){
				aContacts[i] = new AUser(u.getContacts().get(i));
			}
		}
	}

	@Override
	public String getCountry(){
		return super.getCountry().replace("&nbsp;", " ");
	}
	
	private static final long serialVersionUID = 6631244688053295847L;

	@Override
	public int describeContents() {
		return 0;
	}
	
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(super.getId().intValue());
		dest.writeString(super.getFirstname());
		dest.writeString(super.getLastname());
		dest.writeString(super.getGender());
		dest.writeString(super.getPhone());
		dest.writeString(super.getWebpage());
		dest.writeString(super.getDblp());
		dest.writeString(super.getCity());
		dest.writeString(super.getCountry());
		dest.writeString(super.getAddress());
		dest.writeString(super.getZip());
		dest.writeString(super.getMail());
		dest.writeString(super.getTw_access_token());
		dest.writeString(super.getTw_access_secret());
		dest.writeParcelableArray(aContacts, 0);
	}

	public AUser[] getContactArray() {
		return aContacts;
	}

	public static final Parcelable.Creator<AUser> CREATOR = new Parcelable.Creator<AUser>() 
	{ 
		public AUser createFromParcel(Parcel in) 
		{ 
			return new AUser(in); 
		} 

		public AUser[] newArray(int size) 
		{ 
			return new AUser[size]; 
		} 
	};

	public boolean checkTwitter() {
		return getTw_access_token()!=null&&!getTw_access_token().equals("")&&getTw_access_secret()!=null&&!getTw_access_secret().equals("");
	}



}
